//package com.group.eams.interceptor;
//
//import com.group.eams.pojo.entity.Permission;
//import com.group.eams.service.PermissionService;
//import com.group.eams.threadlocal.UserThreadLocal;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.List;
//
///**
// * com.group.eams.interceptor
// * User: 恩哲欣
// * Date: 2024/10/29 14:03
// * Motto: Where there is a will, there is a way!
// * Description:
// * Version: V1.0
// */
//@Slf4j
//public class PermissionInterceptor implements HandlerInterceptor {
//
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        //1.配置不拦截器的资源 springmvc.xml
//
//        //2.获取用户访问的uri
//        String uri = request.getRequestURI();
//        log.debug("当前访问的uri:{}",uri);
//
//        //3.查询用户所有的权限
//        List<Permission> permissionList = permissionService.findPermissionByUserId(UserThreadLocal.get().getId());
//
//        //4.判断用户是否拥有访问该资源的权限 有就放行
//        boolean isOk=false;
//
//        for(Permission permission:permissionList){
//            if(permission.getUri().equals(uri)){
//                isOk=true;
//                break;
//            }
//        }
//        //5.判断是否放行
//        if(!isOk){
//            log.debug("当前用户没有访问:{}的权限",uri);
//            ResponseUtils.responseToJson(response,JsonUtils.objectToJson(Result.buildFail(ResultEnum.NO_PERMISSION)));
//            return false;
//        }
//
//
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//
//    }
//}
